package test;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.lwq.project.utils.UtilsTools;

/**
* @author 作者 linweiqiang
* @version 创建时间：2017年11月14日 下午5:26:27
* 类说明
*/
public class DownloadImage {
	public static void downImg(List<String> list , String path){
		for (String url : list) {
			byte [] data = getByteByUrl(url);
			byte [] b = new byte[10];
			if(data==null)
				continue;
			for (int i = 0; i < b.length; i++) {
				b[i] = data[i];
			}
//			String type = ByteTFFile.getImgType(b);
//			String type = GetFileType.getTypeByByte(b,url);
			
			String name = url.substring(url.lastIndexOf("/") ).split("[?]")[0];
			Thread t = new Thread(new Runnable() {
				public void run() {
					ByteTFFile.byte2File(data, path +  name);
				}
			});
			t.run();
		}
	}
	
	public static byte[] getByteByUrl(String url){
		if(url.matches("^https[^\"']*"))
			return MyUrlRequest.https403Request(url);
		if(url.matches("^http[^\"']*"))
			return MyUrlRequest.http403Request(url);
		if(url.matches("^//[^\"']*"))
			return MyUrlRequest.http403Request("http:" + url);
		if(url.matches("^data[^\"']*"))
			return Base64TFImage.base642Image(url);
		return null;
	}

	
	public static void main(String[] args) {
//		String html = MyUrlRequest.httpRequestString("http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gbk&word=%CD%BC%C6%AC&fr=ala&ala=1&alatpl=others&pos=0", "GET", null);
//		String html = MyUrlRequest.httpRequestString("http://www.cs1.xin", "GET", null);
//		List<String> list = MyJsoupHtml.getImgUrl(html);
//		downImg(list, "D://images");
		String a = "http://www.cs1.xin";
		System.out.println(a.substring(a.lastIndexOf(".")));
	}
}
